package com.hspedu.threaduse;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/14
 * @time 20:57
 */
public class Thread01 {
    public static void main(String[] args) throws InterruptedException {
        //现在的Cat已经可以作为线程使用了
        Cat cat = new Cat();
        cat.start();

        for(int i = 0; i < 60; i++) {
            System.out.println("主线程 i=" + i +" "+Thread.currentThread().getName());
            //让主线程休眠
            Thread.sleep(1000);
        }
    }
}

class Cat extends Thread {
    int times = 0;

    /**
     * 往往重写run方法，实现自己的逻辑
     */
    @Override
    public void run() {
        while (true) {
            System.out.println("喵喵喵，我是一只小猫咪" + (++times) + Thread.currentThread().getName());


            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (times == 80)
                break;
        }
    }
}
